﻿@using Z10Cabbage.Entity;
@using Z10Cabbage.Entity.Helper;
@using Z01Beetle.Entity;
@model Zippy.Data.Collections.PaginatedList<Z10Order>
@{
    ViewBag.Title = "销售订单列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var isAdmin = EAP.Logic.Helper.IsAdministrator();
}
<script type="text/javascript" src="/content/scripts/pagemvc.js"></script>
<script type="text/javascript">
		var pageSize = @ViewBag.PageSize;
		var controller = "/Z10SaleOrder";
		var sortUrl = "@Model.ToSortUrl()";
		
		var curChangeBtn;
		function ChangeCustomer(cid, oid, title){
			$.post("/Z10Order/ChangeOrderCustomer/", {oid:oid, cid:cid}, function(res){
				if (!res.state){
					parent.$.jshowtip(res.message, "error", 1);
					return;
				}
				parent.$.jshowtip("修改成功！", "success", 1);
				curChangeBtn.next().html(title);
				$("#dSelPanel").hide();            
			}, 'json');
		}

		$(function () {
			$("#bQuery").click(function () {
				window.location.href = controller + '/Index?PageSize=' + pageSize 
					+ "&qCreateDateStart=" + encodeURIComponent($("#qCreateDateStart").val())
					+ "&qCreateDateEnd=" + encodeURIComponent($("#qCreateDateEnd").val());			
			});

			$("#qCreateDateStart").datepicker({dateFormat:"yy-mm-dd"});
			$("#qCreateDateEnd").datepicker({dateFormat:"yy-mm-dd"});

			$(".xdetail").unbind("click").bind("click",function(){
				var id = $(this).attr("rel");
				parent.go2("/Z10Order/Detail/" + id + "/?returnUrl=@HttpUtility.UrlEncode(Request.RawUrl)");
			});
			$(".xputout").click(function () {
				var id = $(this).attr("rel");
				parent.go2("/Z10OutDepot/Putout/" + id+ "/?returnUrl=@HttpUtility.UrlEncode(Request.RawUrl)");
			});
			$(".xpay").click(function(){
				var id = $(this).attr("rel");
				parent.go2("/Z10Order/Pay/" + id+ "/?returnUrl=@HttpUtility.UrlEncode(Request.RawUrl)");
			});
			$(".modiCus").click(function(){
				curChangeBtn = $(this);
				var oid = curChangeBtn.attr("rel");
				$("#ifSel").attr("src", "/z10order/selectcustomer/?act=modiOrder&orderID="+oid+"&qCustomerType=@((int)EAP.Logic.Z01.CustomerTyps.Customer)");
				$("#dSelPanel").show();
			});

            var xoid;
            $(".xbtn_status").click(function(){
                $(".xchangeStatus").hide();
                $(this).next().show();
                xoid=$(this).attr("data-oid");
            });
            $(".xchangeStatus button").click(function(){
                $(".xchangeStatus").hide();                
            });

			$("input[name='xosts']").click(function(){
                xthis = $(this);
                xsts=xthis.val();
                isAdd=xthis.prop('checked');
                $.post("/z10order/changestatus/",{oid:xoid,xsts:xsts,isAdd:isAdd},function(res){
                    if (!res.state){
                        alert(res.message);
                        return;
                    }
                    alert("更新成功。");

                },'json');
            });

		});
</script>
<div style="left: 261px; top: 10px; display: none" id="dSelPanel" class="pop-box w500">
    <h2 rel="title">
        <a title="关闭" class="close" href="javascript:;">关闭</a><span id="selTitle">选择客户</span></h2>
    <div class="con">
        <div class="top">
            <div style="font-size: 20px; font-family: 黑体; font-weight: bold; text-align: left">
                请选择客户</div>
        </div>
        <div class="main" style="height: 500px;">
            <iframe id="ifSel" width="100%" height="100%" frameborder="0"></iframe>
        </div>
    </div>
</div>
<div id="contents">
    <div id="top">
        <div class="con clearfix">
            <div class="fl">
                @Html.Raw(ViewBag.TopMenu)
            </div>
        </div>
    </div>
    <div id="main">
        @{var orCol = Request["orderCol"]; int iorCol = orCol.ToInt32(); }
        <table cellspacing="0" cellpadding="0" border="0" rel="main" class="list-table">
            <tr rel="title">
                <th>
                    编号及项目概况
                    @if (iorCol == 1)
                    {
                        <i title="点击排序" class="icon i_sort i_asc" rel="2"></i>
                    }
                    else if (iorCol == 2)
                    {
                        <i title="点击排序" class="icon i_sort i_desc" rel="1"></i>
                    }
                    else
                    { 
                        <i title="点击排序" class="icon i_sort i_nosort" rel="1"></i>
                    }
                </th>
                <th>
                    合同额
                </th>
                <th>
                    应收
                </th>
                <th>
                    已收
                </th>
                <th>
                    客户
                    @if (iorCol == 3)
                    {
                        <i title="点击排序" class="icon i_sort i_asc" rel="4"></i>
                    }
                    else if (iorCol == 4)
                    { 
                        <i title="点击排序" class="icon i_sort i_desc" rel="3"></i>
                    }
                    else
                    {
                        <i title="点击排序" class="icon i_sort i_nosort" rel="3"></i>
                    }
                </th>
                <th>
                    下单日期
                    @if (iorCol == 5)
                    { <i title="点击排序" class="icon i_sort i_asc" rel="6"> </i>}
                    else if (iorCol == 6)
                    { <i title="点击排序" class="icon i_sort i_desc" rel="5"> </i>}
                    else
                    { <i title="点击排序" class="icon i_sort i_nosort" rel="5"></i>}
                </th>
                <th>
                    状态
                </th>
                <th>
                    创建时间
                    @if (iorCol == 11)
                    { <i title="点击排序" class="icon i_sort i_asc" rel="12"> </i>}
                    else if (iorCol == 12)
                    { <i title="点击排序" class="icon i_sort i_desc" rel="11"> </i>}
                    else
                    { <i title="点击排序" class="icon i_sort i_nosort" rel="11"></i>
                    }
                </th>
                <th style="width: 140px">
                    操作
                </th>
            </tr>
            @{ var db = Zippy.Data.StaticDB.DB; }
            @if (Model.Count > 0)
            {
                foreach (var item in Model)
                {
                    var _orderStatus = item.OrderStatus ?? 0;

                    var storedsome = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.OuttedSome);
                    var stored = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.Outted);
                    var paidsome = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.PaidSome);
                    var paid = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.Paid);
                    var finished = ((item.OrderStatus ?? 0) & (int)EAP.Logic.Z10.OrderStatus.Finished);

                    var items = db.Take<Z10OrderItem>("OrderID=@OrderID", db.CreateParameter("OrderID", item.OrderID ?? 0));
                    string sitems = "";

                    items.ForEach(delegate(Z10OrderItem xitem)
                    {
                        sitems += xitem.Title + " ";
                    });
							   
                <tr rel="item">
                    <td>
                        <a href="/Z10Order/Detail/@item.OrderID?ReturnUrl=@HttpUtility.UrlEncode(Request.RawUrl)"
							title='@HttpUtility.HtmlEncode(sitems)'>
                            @item.OrderID，@sitems.ToStringChopped(30)</a>
                    </td>
                    <td class="tr">
                        @((item.Total ?? 0).ToString("0.00"))
                    </td>
                    <td class="tr">
                        @((item.FeeShould ?? 0).ToString("0.00"))
                    </td>
                    <td class="tr">
                        @((item.FeePaid ?? 0).ToString("0.00"))
                    </td>
                    @{                    var customer = item.GetCustomer(db);                    }
                    <td>
                        @if (!_orderStatus.BitIs(EAP.Logic.Z10.OrderStatus.Finished) && isAdmin)
                        { 
                            <input type="button" value="改" class='modiCus' rel="@item.OrderID" />
                        }
                        <span>@(customer == null ? "" : customer.Title)</span>
                    </td>
                    <td>
                        @if (item.DateOrder != null)
                        {
                            <text>@item.DateOrder.Value.ToString("yyyy-MM-dd")</text>
                        }
                    </td>
                    <td>
                        @((typeof(EAP.Logic.Z10.OrderStatus)).ToString(item.OrderStatus ?? 0, typeof(Resources.X)))
                    </td>
                    <td>
                        @Html.Raw(item.CreateDate.Value.ToPassedAway())
                    </td>
                    <td>
                        <a href="javascript:;" class="xbtn_status" data-oid="@item.OrderID">状态</a>
                        <div style="width: 100px; position: absolute; border: 1px solid #ccc; padding: 4px;
                            background: #eee; display: none" class='xchangeStatus'>
                            @Html.Raw((typeof(EAP.Logic.Z10.OrderStatus)).ToHtmlControlList("xosts", "checkbox", typeof(Resources.X), item.OrderStatus))
                            <br />
                            <button>
                                关闭</button>
                        </div>
                        <a href="javascript:" class="list" id="action-@item.OrderID">操作</a>
                        <div>
                            <ul class="opt-mmenu" rel="action-@item.OrderID">
                                <li><i class="icon i_detail"></i><a href="javascript:" rel="@item.OrderID" class="xdetail"
									rel="@item.OrderID">详情</a></li>
                            </ul>
                        </div>
                    </td>
                </tr>
                }
            }
            else
            { 
                <!-- 没有数据的时候显示 -->
                <tr rel="noitem">
                    <td colspan="8" class="msg-box h200">
                        没有任何数据
                    </td>
                </tr>
                <!-- 没有数据的时候显示 -->
            }
        </table>
    </div>
</div>
<div class="pop-box pop-query w600" rel="search" style="z-index: 999">
    <div class="con">
        <a rel="close" class="close mr10" href="javascript:;">关闭</a>
        <div class="msg-box msg-contents">
            <table class="query">
                <tr>
                    <td class='tt'>
                        创建时间：
                    </td>
                    <td>
                        <input type='text' class='text' id='qCreateDateStart' />
                        -
                        <input type='text' class='text' id='qCreateDateEnd' />
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </div>
        <div class="bottom">
            <a class="jenter button" href="javascript:;" id='bShowAll'>显示全部<b></b></a> <a class="jenter button active"
                href="javascript:;" id='bQuery'>查询<b></b></a>
        </div>
    </div>
</div>
<div id="bottom">
    @Html.Raw(Model.ToPagerHtml("Z10InventoryOutOrder", "Index", ViewBag.PageSize))
</div>
